﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ComponentModel;
using RestSharp.Serializers;

namespace RATSharp.Model
{
    /// <summary>
    /// Period model
    /// 
    /// Reason why this class is named with small letters is following issue
    /// https://github.com/restsharp/RestSharp/pull/361
    /// I don't want to create my own fork of this library (this change is not in dist WP7 branch yet)
    /// so this is a workaround till pull request would not be in official distribution
    /// </summary>
    [DataContract]
    [SerializeAs(Name = "period")]
    public class period : INotifyPropertyChanged
    {
        /// <summary>
        /// Period id
        /// </summary>
        [DataMember]
        public int? id { get; set; }
        /// <summary>
        /// Period from date
        /// </summary>

        private DateTime fromDate;

        [DataMember]
        [SerializeAs(Name = "fromDate")]
        public DateTime FromDate
        {
            get
            {
                return fromDate;
            }
            set
            {
                if (this.fromDate != value)
                {
                    this.fromDate = value;

                    this.RaisePropertyChanged("FromDate");
                }
            }
        }
        /// <summary>
        /// Period to date
        /// </summary>
        private DateTime toDate;

        [DataMember]
        [SerializeAs(Name = "toDate")]
        public DateTime ToDate
        {
            get
            {
                return toDate;
            }
            set
            {
                if (this.toDate != value)
                {
                    this.toDate = value;

                    this.RaisePropertyChanged("ToDate");
                }
            }
        }
        /// <summary>
        /// Periods pickAction
        /// </summary>
        [DataMember]
        public PickAction pickAction { get; set; }
        /// <summary>
        /// Periods return action
        /// </summary>
        [DataMember]
        public ReturnAction returnAction { get; set; }
        /// <summary>
        /// is period valid
        /// </summary>
       
        private bool valid { get; set; }

        [DataMember]
        [SerializeAs(Name = "valid")]
        public bool Valid
        {
            get
            {
                return valid;
            }
            set
            {
                if (this.valid != value)
                {
                    this.valid = value;

                    this.RaisePropertyChanged("Valid");
                }
            }
        }

        /// <summary>
        /// periods reservation
        /// </summary>
        [DataMember]
        public Reservation reservation { get; set; }


        /// <summary>
        /// overriden for properties visibility
        /// </summary>
        /// <returns>string representation</returns>
        public override string ToString()
        {
            string fromDateAsTime = String.Format("{0:dd.MM. HH:mm}", fromDate);
            string toDateAsTime = String.Format("{0:dd.MM. HH:mm}", toDate);
            return String.Format("Id: {0}, From: {1}, To: {2}, Owner: {3}, PickAction: {4}, ReturnAction: {5}, ObjectName: {6} , Valid: {7}", id, fromDateAsTime, toDateAsTime, reservation.userName, pickAction, returnAction, reservation.objectName, valid);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    /// <summary>
    /// This enum represents objects life cycle. It is placed here because it´s related to every single period.
    /// This is requested in "sliding window time" pickup feature
    /// </summary>
    public enum PickAction
    {
        /// <summary>
        /// object is not pickable
        /// </summary>
        NOT_PICKABLE,
        /// <summary>
        /// object is not picked yet
        /// </summary>
        NOT_PICKED,
        /// <summary>
        /// object is already picked
        /// </summary>
        PICKED
    };

    /// <summary>
    /// This enum represents objects life cycle. It is placed here because it´s related to every single period.
    /// This is requested in "sliding window time" pickup feature
    /// </summary>
    public enum ReturnAction
    {
        /// <summary>
        /// object is already returned
        /// </summary>
        RETURNED,
        /// <summary>
        /// object is not returned
        /// </summary>
        NOT_RETURNED,
        /// <summary>
        /// not returnable object
        /// </summary>
        NOT_RETURNABLE
    };
}
